/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : WinPeripheralDev.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "WinPeripheralDevEvent.h"
#include "NetmenuSetupEvent.h"

INT32S WinPeripheralDevMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinPeripheralDevOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWinPeripheralDevPalette_720P(void)
{
    YUVENTRY mask_para[4] = {0,0,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 18184,0x8000 | 18184,0x8000 | 16392,17592,18152,22116,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinPeripheralDevPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	case OsdSize720p:
           RECT WindowRect720p = {0,0,1280,720};
            pControl->winrect = WindowRect720p;
            CREATEWINDOWPARAM WindowPara720p = {1,{{0,0,1280,720},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetWinPeripheralDevPalette_720P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&WindowPara720p);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinPeripheralDev_720P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	case OsdSize720p:
            CREATEWINDOWPARAM window_para720p = {1,{{0,0,1280,720},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinPeripheralDevPalette_720P};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinPeripheralDev_720P",WS_OVERLAPPEDWINDOW,
		                      0,0,1280,720,NULL, (INT32S)&window_para720p,WinPeripheralDevMsgProc_720P) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetWinConPeripheralDevPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	case OsdSize720p:
            pControl->winrect.top = pControl->parent->winrect.top + 120;
            pControl->winrect.left = pControl->parent->winrect.left + 440;
            pControl->winrect.width = 400;
            pControl->winrect.height = 360;
            pControl->draw_info_num = 2;
            RECT DrawRect720p[2] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,360,324},
            {pControl->winrect.left + 120,pControl->winrect.top + 330,200,30},
            };
            for(iLoop=0; iLoop < 2; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect720p[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S WinConPeripheralDevMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinConPeripheralDevOnShow(hwnd, lpParam) ;
        case WM_PAINT:
            return WinConPeripheralDevOnPaint(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return WinConPeripheralDevOnKeyPress(hwnd, lpParam) ;
        default:
            return WinConPeripheralDevOnOtherEvent(hwnd, msg_type, lpParam) ;
    }
    return 0 ;
}
 
HWND *CreateControlWinConPeripheralDev_720P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- WinConPeripheralDev
    HWND *pNewControl;
    switch(CurOsdSize){
	case OsdSize720p:
            pNewControl = AWCreateWinControl("TControl","WinConPeripheralDev_720P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      270,120,400,360,pParent,0,WinConPeripheralDevMsgProc_720P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 2;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO DrawDatas720p[2] = {
                          {0,0,0,0,(INT32U)ICON_PC_CONNECT,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA}};
            memcpy(pNewControl->draw_info,DrawDatas720p, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinPeripheralDev_720P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinPeripheralDev = CreateControlWinPeripheralDev_720P(NULL,CurrentOsdSize);
    SetWinPeripheralDevPos(pWinPeripheralDev,CurrentOsdSize);

    pNewControl= CreateControlWinConPeripheralDev_720P(pWinPeripheralDev,CurrentOsdSize);
    SetWinConPeripheralDevPos_720P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinPeripheralDev;
    pWin->pFocusControl = AWFindWinCtrlByName("WinConPeripheralDev_720P");
    return pWinPeripheralDev;
}

void WinResetWinPeripheralDevControlsPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinPeripheralDev
            SetWinPeripheralDevPos_720P(pControl,CurOsdSize) ;
            break ;
        case 1://WinConPeripheralDev
            SetWinConPeripheralDevPos_720P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinPeripheralDevPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinPeripheralDev_720P");
    if(pControl == NULL) return ;

    WinResetWinPeripheralDevControlsPos_720P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinPeripheralDevPos_720P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

